﻿'Copyright (c) 2011 Kraigose Studios (Kraig C)

'Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
' to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
' and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

'The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

'THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
' IN THE SOFTWARE.

Imports System.IO
Imports System.Text.RegularExpressions

Module modINI

    Public Structure PropertiesInfo
        Public animtype As Integer
        Public animframes As Integer
        Public offsetX As Integer
        Public offsetY As Integer
        Public speed As Integer
    End Structure

    Public Sub DumpINI(ByRef cartf As ArtFile, ByRef folder As String)
        Dim strFile As String = currFileNum.ToString().PadLeft(3, "0")
        strFile = strFile.ToLower()
        Dim strFullName As String = folder + "\" + "props" + strFile + ".ini"
        Dim inisw As New StreamWriter(strFullName)

        If verbose Then
            Console.WriteLine("Writing Header for INI file #" + strFile)
        End If

        inisw.WriteLine("; Generated by Art2Png [export mode]")
        inisw.WriteLine("; This file stores data for the properties")
        inisw.WriteLine("; of the corrisponding art file.")
        inisw.WriteLine("[Property.Header]")
        inisw.WriteLine("filenum = " + currFileNum.ToString())
        inisw.WriteLine()

        Dim i As Integer
        Dim numtiles As Integer = cartf.LocalEnd - cartf.LocalStart + 1

        For i = 1 To numtiles
            Dim tilenumcurrfile As Integer = cartf.LocalStart + i - 1
            Dim propin As PropertiesInfo = GetProps(cartf, i)
            If verbose Then
                Console.WriteLine("Writing tile info for tile #" + tilenumcurrfile.ToString())
            End If
            Dim tcnstr As String = tilenumcurrfile.ToString.PadLeft(4, "0")
            inisw.WriteLine("[tile" + tcnstr.ToString() + "]")
            inisw.WriteLine("fnum = " + propin.animframes.ToString())
            inisw.WriteLine("type = " + propin.animtype.ToString())
            inisw.WriteLine("offx = " + propin.offsetX.ToString())
            inisw.WriteLine("offy = " + propin.offsetY.ToString())
            inisw.WriteLine("aspd = " + propin.speed.ToString())
            inisw.WriteLine()
        Next

        inisw.Close()

    End Sub

    Public Sub ReadINI(ByRef cArtF As ArtFile, ByRef folder As String)
        Dim strFile As String = currFileNum.ToString().PadLeft(3, "0")
        strFile = strFile.ToLower()
        Dim strFullName As String = folder + "\" + "props" + strFile + ".ini"
        Dim inisr As New StreamReader(strFullName)

        Dim headerRead As String = False

        If verbose Then
            Console.WriteLine("Reading Header for INI file #" + strFile)
        End If

        Dim currReadline As String = inisr.ReadLine()
        Dim currReadlineB As String = ""

        While Not inisr.EndOfStream
            Dim storeindex As Integer = -1
            If currReadline.IndexOf(";") <> 1 Then
                currReadline = ""
            Else
                For i = 0 To currReadline.Length
                    If (currReadline.Substring(i, 1)) = ";" Then
                        storeindex = i
                        i = currReadline.Length + 1
                    End If
                    If storeindex <> -1 Then
                        currReadline = currReadline.Substring(0, storeindex)
                    End If
                Next i
            End If
            If currReadline <> "" Then
                currReadlineB = currReadline
            End If

            If currReadlineB <> "" Then

            End If

        End While

    End Sub
End Module
